//
//  ResidencePermitViewModel.m
//  Jyxt
//
//  Created by 王炜光 on 2017/8/21.
//  Copyright © 2017年 DaLian Rental Housing Management. All rights reserved.
//

#import "ResidencePermitViewModel.h"
#import "NetTool.h"
#import "UserCenterViewModel.h"
#import <MJExtension.h>
#import "DatabaseTool.h"
#import <LemonBubble.h>

#define UTOKEN @"uToken"
#define UNAME @"uName"
@implementation ResidencePermitViewModel
+ (void)getResidencePermitListWithData:(NSDictionary *)data success: (void (^)(id response)) success failed: (void (^)(NSString *reason))failed{

    
    [NetTool postWithUrl: APIURL(API_RESIDENT_PERMIT_LIST) data: data onSuccess:^(NSDictionary *response) {
        if ([response[@"success"] boolValue]) {
            success(response);
        }
        else{
            failed(response[@"errmsg"]);
        }
    } onError:^(NSError *error) {
        failed(@"无法连接到服务器");
    }];
}

+ (void)getResidencePermitDetailWithData:(NSDictionary *)data success:(void (^)(id response))success failed:(void (^)(NSString *reason))failed{
    [NetTool postWithUrl: APIURL(API_RESIDENT_PERMIT_DETAIL) data: data onSuccess:^(NSDictionary *response) {
        if ([response[@"success"] boolValue]) {
            success(response);
        }
        else{
            failed(response[@"errmsg"]);
        }
    } onError:^(NSError *error) {
        failed(@"无法连接到服务器");
    }];
}
+ (void)postResidencePermitApplyWithData:(NSDictionary *)data success:(void (^)(id response))success failed:(void (^)(NSString *reason))failed{
    [NetTool postWithUrl: APIURL(API_RESIDENT_PERMIT_APPROVE_APPLY) data: data onSuccess:^(NSDictionary *response) {
        if ([response[@"success"] boolValue]) {
            success(response);
        }
        else{
            failed(response[@"errmsg"]);
        }
    } onError:^(NSError *error) {
        failed(@"无法连接到服务器");
    }];
}

+ (void)refusedResidencePermitApplyWithData:(NSDictionary *)data success:(void (^)(id response))success failed:(void (^)(NSString *reason))failed{
    [NetTool postWithUrl: APIURL(API_RESIDENT_PERMIT_REJECT_APPLY) data: data onSuccess:^(NSDictionary *response) {
        if ([response[@"success"] boolValue]) {
            success(response);
        }
        else{
            failed(response[@"errmsg"]);
        }
    } onError:^(NSError *error) {
        failed(@"无法连接到服务器");
    }];
}

+ (void)getResidencePermitApplyImageWithData:(NSDictionary *)data success:(void (^)(id response))success failed:(void (^)(NSString *reason))failed{
    [NetTool postImageWithUrl:APIURL(API_RESIDENT_GET_ATTACHMENT) data:data onSuccess:^(NSDictionary *response) {
        success(response);
        
    } onError:^(NSError *error) {
        
       failed(@"无法连接到服务器");
    }];
}

+ (NSString *)dictionaryToJson:(NSDictionary *)dic{
    
    NSString *tempStr = @"{";
    for (NSString *key in dic.allKeys) {
        tempStr = [NSString stringWithFormat:@"%@'%@':'%@',",tempStr,key,dic[key]];
    }
    tempStr = [tempStr stringByReplacingCharactersInRange:NSMakeRange(tempStr.length-1, 1) withString:@"}"];
    return tempStr;
}

@end
